package com.niit.order.service.impl;

import com.niit.feign.clients.UserClient;
import com.niit.feign.pojo.User;
import com.niit.order.mapper.OrderMapper;
import com.niit.order.pojo.Order;
import com.niit.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 通过Feign-Api进行远程调用的实现方式
 * @author yaojianfeng
 */
@Service("orderServiceFeign")
public class OrderServiceFeignImpl implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;

    @Value("${server.port}")
    private String serverPort;

    @Override
    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order =   orderMapper.findById(orderId);
        if (order != null) {
            order.setServerPort(serverPort);

            //2 通过UserClient,发送请求到user模块
            User user = userClient.findUserById(order.getUserId()+"");
            //3.封装user信息到order中
            order.setUser(user);
        }
        // 4.返回
        return order;
    }
}
